import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },

  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },

  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [{
      path: 'dashboard',
      name: 'Dashboard',
      component: () => import('@/views/dashboard/index'),
      meta: { title: 'Dashboard', icon: 'dashboard', required: true }
    }]
  },
  {
    path: '/article',
    component: Layout,
    redirect: '/article/allArticles',
    children: [{
      path: 'allArticles',
      name: 'Example',
      component: () => import('@/views/table/index'),
      meta: { title: '文章管理', icon: 'table', required: true }
    }]
  },
  {
    path: '/addArticle',
    component: Layout,
    redirect: '/addArticle/createArticle',
    children: [{
      path: 'createArticle',
      name: 'Tree',
      component: () => import('@/views/editor/index'),
      meta: { title: '编辑文章', icon: 'table', required: true }
    }]
  },
  {
    path: '/structure',
    component: Layout,
    redirect: '/structure/libraryStructure',
    children: [{
      path: 'libraryStructure',
      name: 'Structure',
      component: () => import('@/views/tree/index'),
      meta: { title: '文库结构', icon: 'table', required: true }
    }]
  },
  {
    path: '/timeLine',
    component: Layout,
    redirect: '/dashboard',
    children: [{
      path: 'allTimeLine',
      name: 'allTimeLine',
      component: () => import('@/views/TimeLine'),
      meta: { title: '时间线管理', icon: 'dashboard', required: true }
    }]
  },
  {
    path: '/myWareHouse',
    component: Layout,
    redirect: 'myWareHouse/picture',
    meta: { title: '后端配置' },
    children: [
      {
        path: 'picture',
        component: () => import('@/views/wareHouse/pictrue/index'),
        name: 'picture',
        meta: { title: '图片管理' }
      },
      {
        path: 'config',
        component: () => import('@/views/wareHouse/Config'),
        name: 'config',
        meta: { title: '主设置' }
      }
    ]
  },
  {
    path: 'external-link',
    component: Layout,
    children: [
      {
        path: 'https://gitee.com/Cjx_723/dashboard/projects',
        meta: { title: '我的Gitee', icon: 'link' }
      }
    ]
  },
  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({

  mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
